
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui"
	xmlns:c="http://java.sun.com/jsp/jstl/core">

<ui:composition template="/template_padrao.xhtml">

	<ui:define name="content">

		<f:event type="preRenderView"
			listener="#{fornecedorMaterialMB.beginConversation()}" />


		<h2>Consulta Fornecedores Materiais</h2>

		<h:form id="form_con_materiais">


			<p:fieldset styleClass="fielSetPadrao">
				<legend>Pesquisa</legend>

				<div class="buttonNew">
					<p:commandButton value="Novo"
						action="#{fornecedorMaterialMB.novo()}" ajax="false" />
				</div>

				<br />
				<table class="table">

					<tr>	
						
						<td><h:outputText value="Material" /></td>
						<td><p:inputText
								value="#{fornecedorMaterialMB.descriacaoMaterialPesquisa}" /></td>
					</tr>
					
					<tr>
						<td>Preço</td>
						<td><p:inputText
								value="#{fornecedorMaterialMB.precoMaterialPesquisa}"
								label="Preço">
								<f:convertNumber type="number" />
							</p:inputText></td>					
					</tr>
					
					<tr>
						<td><h:outputLabel value="Fornecedor" /></td>
						<td><p:selectOneMenu 
								value="#{fornecedorMaterialMB.fornecedorMaterialPesquisa}">
								<f:selectItem itemLabel="Selecione"/>
								<f:selectItems value="#{fornecedorMaterialMB.listaEmpresas}" />
							</p:selectOneMenu></td>
					</tr>
					
					<tr> 
						<td><p:commandButton value="Buscar"	action="#{fornecedorMaterialMB.pesquisar()}" ajax="false" /></td>
					</tr>
				</table>

			</p:fieldset>

			<br />

			<p:dataTable value="#{fornecedorMaterialMB.listaForncedorMaterial}"
				var="forn" paginator="true" rows="10" paginatorPosition="bottom"
				id="table_list_materiais"
				rendered="#{fornecedorMaterialMB.listaForncedorMaterial.size() > 0}">


				<p:column>
					<f:facet name="header">
						<h:outputText value="Fornecedor" />
					</f:facet>

					<h:outputText value="#{forn.pessoaJuridica.nomeFantasia}" />

				</p:column>

				<p:column>
					<f:facet name="header">
						<h:outputText value="Material" />
					</f:facet>
					<h:outputText value="#{forn.material.descricaoMaterial}" />
				</p:column>

				<p:column>
					<f:facet name="header">
						<h:outputText value="Preço" />
					</f:facet>
					<h:outputText value="#{forn.valor}">
						<f:convertNumber currencySymbol="R$" type="currency" />
					</h:outputText>

				</p:column>

				<p:column>
					<f:facet name="header">
						<h:outputText value="Medida" title="Unidade Medida"/>
					</f:facet>
					<h:outputText value="#{forn.material.unidadeMedida.toString()}" />
				</p:column>
				
				
				<p:column>
					<f:facet name="header">
						<h:outputText value="Situação" title="Situação do Material" />
					</f:facet>
					<h:outputText rendered="#{forn.ativo}" value="Ativo"/>
					<h:outputText rendered="#{!forn.ativo}" value="Inativo"/>
				</p:column>

				<p:column>
					<f:facet name="header">
						<h:outputText value="Ações" />
					</f:facet>

					<h:commandLink action="#{fornecedorMaterialMB.editar()}"
								   title="Editar">
						<f:setPropertyActionListener
							target="#{fornecedorMaterialMB.fornecedorMaterialSelecionado}"
							value="#{forn}" />
						<h:graphicImage value="/images/editar.png"
							styleClass="buttonEditDeletSearch" />
					</h:commandLink>

					<p:commandLink oncomplete="cdRemoveFornecedorMaterial.show()"
								 title="Excluir">
						<f:setPropertyActionListener
							target="#{fornecedorMaterialMB.fornecedorMaterialSelecionado}"
							value="#{forn}" />
						<h:graphicImage value="/images/excluir.png"
							styleClass="buttonEditDeletSearch" />
					</p:commandLink>

				</p:column>
			</p:dataTable>

		</h:form>

		<h:form>
			<p:confirmDialog message="Deseja realmente excluir?" 
							 header="Excluir"
							 severity="alert" 
							 modal="true" 
							 widgetVar="cdRemoveFornecedorMaterial">
				<p:outputPanel>
					<h:form>
						<p:commandButton action="#{fornecedorMaterialMB.deletar()}"
										 value="Sim" 
										 ajax="false">
						</p:commandButton>
						
						<p:commandButton value="Não" 
										 oncomplete="cdRemoveFornecedorMaterial.hide()" 
										 ajax="false"/>
					</h:form>
				</p:outputPanel>
			</p:confirmDialog>
		</h:form>

	</ui:define>

</ui:composition>

</html>